package com.tools.web.email;

import com.tools.common.object.Note;

import java.util.Locale;

/**
 * 邮件发送方式的枚举类
 * */
@Note("邮件发送方式的枚举类")
public enum MailSendEnum {

    TO("to", "发送"),
    BCC("bcc", "密送"),
    CC("cc", "抄送");

    private final String name;
    private final String text;

    MailSendEnum(String name, String text) {
        this.name = name;
        this.text = text;
    }

    public String getName() {
        return name;
    }

    public String getText() {
        return text;
    }

    public boolean eq(String name) {
        return this.name.equals(name);
    }

    public boolean ignoreCaseEq(String name) {
        return this.name.equalsIgnoreCase(name);
    }

    @Override
    public String toString() {
        return this.name();
    }

    @Note("安全地根据邮件发送方式的名称获取枚举实例，获取不到不会抛异常")
    public static MailSendEnum getEnumSafe(String name){
        switch (name.toLowerCase(Locale.ROOT)) {
            case "to": return TO;
            case "bcc": return BCC;
            case "cc": return CC;
            default: return null;
        }
    }


    @Note("根据邮件发送方式的名称获取枚举实例，获取不到会抛异常")
    public static MailSendEnum getEnum(String name) {
        MailSendEnum mailSend = getEnumSafe(name);
        if(mailSend == null) throw new IllegalArgumentException("不知道 " + name + " 对应什么枚举");
        return mailSend;
    }
}
